Use the Text Block nodes to show a small amount of text in your application. Text block node uses the font you select to render the text. Use Text Block 3D to show text in 3D space and Text Block 2D to show text in 2D space.
The default font in Kanzi is Fira Sans Regular. It is stored in <KanziInstallation>/Studio/Asset Library/Fonts. When you want to use your own font, import it to your Kanzi Studio project. See Importing fonts.
Note that in order to properly render text content you have to use a font that includes the glyphs of the languages you want to include in your Kanzi application.
When you want the background of the text block nodes to be transparent, you need to render the nodes in the scene graph of your Kanzi application in the correct order. See Rendering transparent nodes.
To add text to your application:
To dynamically change the size of text in a Text Block node, use the Scale property field of either Render Transformation or Layout Transformation properties, instead of the Font Size property. For example, use this approach when you want to animate the size of text in a Text Block node.
When you use the Font Size property to dynamically scale the text, Kanzi creates multiple textures for different font sizes and does not release them from the memory.
Use brushes to set the background of 2D nodes. In Kanzi all 2D nodes by default have transparent background.
To set the background:
To create a Text Block 3D object:
// Create a Text Block 3D node named Text block. TextBlock3DSharedPtr textBlock = TextBlock3D::create(domain, "Text block");
To set the font of a text block:
// Set the font used by the text block node using the resource ID. textBlock->setFontResourceID(ResourceID("MyFont"));
To add the text shown by a text block:
// Set the content of the text block node to read Hello world!. textBlock->setText("Hello\nworld!");
To adjust the appearance of the text:
// Set the style of the text shown by the text block node. // Set the size of the font to 90.0f. textBlock->setFontSize(90.0f); // Set the color of the font to blue. textBlock->setFontColor(KanziThemeBlue); // Align the text in the text block to the right. textBlock->setTextHorizontalAlignment(TextBlockConcept::TextHorizontalAlignmentRight);
For details, see the API reference.
To create a Text Block 2D object:
// Create a Text Block 2D object named Text layer. TextBlock2DSharedPtr textLayer = TextBlock2D::create(domain, "Text layer");
To set the font of a text block:
// Set the font used by the text block using the resource ID. textLayer->setFontResourceID(ResourceID("MyFont"));
To add the text shown by a text block:
// Set the content of the text block to read Hello world!. textLayer->setText("Hello\nworld!");
To adjust the appearance of the text:
// Set the style of the text shown by the text block. // Set the line spacing to 1.5f. textLayer->setLineSpacing(1.5f); // Set the size of the font to 36.0f. textLayer->setFontSize(36.0f); // Set the color of the font to blue. textLayer->setFontColor(KanziThemeBlue); // Align the text in the text block to the right. textLayer->setTextHorizontalAlignment(TextBlockConcept::TextHorizontalAlignmentRight);
For details, see the API reference.